package com.iemes.controller.warehouse;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.EnterstorageFormMap;
import com.iemes.entity.OvertimeanalyzeFormMap;
import com.iemes.entity.UserFormMap;
import com.iemes.mapper.warehouse.EnterstorageMapper;
import com.iemes.mapper.warehouse.OvertimeanalyzeMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;
import com.iemes.util.MyDateUtils;

@RequestMapping("/overtimeabolish_form/")
@Controller
public class Overtimeabolish_FormController extends BaseController {
	
	@Inject
	private OvertimeanalyzeMapper overtimeanalyzeMapper;

	// 查看超期报废申请表，显示按钮。
	@RequestMapping("overtimeabolish_form")
	public String overtimeabolish_form(Model model) {
		model.addAttribute("res", findByRes());
		return Common.BACKGROUND_PATH + "/warehouse/overtimeabolish_form_list";
	}

	// 超期报废申请表分页
	@ResponseBody
	@RequestMapping("overtimeabolish_form_findByPage")
	public PageView findByPage(String pageNow, String pageSize) throws Exception {
		OvertimeanalyzeFormMap overtimeanalyzeFormMap = getFormMap(OvertimeanalyzeFormMap.class);
		overtimeanalyzeFormMap.put("formCategory", 2);
//		List<Map<String, Object>> over = overtimeanalyzeMapper.getAllGt7(overtimeanalyzeFormMap);
		//测试用，以后须换成上面的getAllGt7
		List<Map<String, Object>> list=overtimeanalyzeMapper.getAll(overtimeanalyzeFormMap);
		LuogicPaging(pageNow, pageSize, list);
		return pageView;
	}

	// 编辑超期报废申请表
	@RequestMapping("overtimeabolish_form_edit")
	public String editUI(Model model) throws Exception {
		String id = getPara("id");
		if(Common.isNotEmpty(id)){
			//获取全部用户
			UserFormMap userFormMap=getFormMap(UserFormMap.class);
			List<UserFormMap> users=baseMapper.findByNames(userFormMap);
			model.addAttribute("users",users);
			//获得相同enterId的超期报废申请表
			OvertimeanalyzeFormMap over=overtimeanalyzeMapper.getById(id);
			model.addAttribute("over",over);
		}
		return Common.BACKGROUND_PATH + "/warehouse/overtimeabolish_form_edit";
	}
	
	// 修改超期报废申请表
	@ResponseBody
	@RequestMapping(value = "overtimeabolish_form_editEntity")
	@Transactional(readOnly=false)//需要事务操作必须加入此注解
	@SystemLog(module = "编辑超期报废申请表", methods = "超期报废申请表-修改超期报废申请表") // 凡需要处理业务逻辑的.都需要记录操作日志
	public String editEntity(HttpServletRequest request) throws NumberFormatException, Exception {
		OvertimeanalyzeFormMap overtimeanalyzeFormMap=getFormMap(OvertimeanalyzeFormMap.class);
		overtimeanalyzeFormMap.put("formCategory", 2);
		baseMapper.editEntity(overtimeanalyzeFormMap);
		return "success";
	}
}